{include file=header.html}
<script language="javascript" type="text/javascript" src="{res file=DatePicker/WdatePicker.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery-1.2.6.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/jquery.funkyUI.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/common.js}"></script>
<script language="javascript" type="text/javascript" src="{lib file=jquery.plugins/jquery.validate.js}"></script>
<script language="javascript" type="text/javascript" src="{res file=js/select.js}"></script>
<script type="text/javascript">
$(function() {
	$('select[select_input="select_input"]').each(function(i) {
		init_select_input($(this));
	});
	$('div.select-input').each(function(i) {
		$(this).css('z-index', $('div.select-input').length - i);
	});
	$('#add_fabric_info').click(function() {
		var tr = $('<tr><th align="right">{$lang.desc}：</th><td class="tab-align-l" colspan="3"></td><th align="right">{$lang.fabric_shop_name}：</th><td class="tab-align-l" colspan="3"></td><td colspan="2" align="left"></td></tr>');
		var sel_input = $($('#fabric_shop_data').html());
		sel_input.attr('select_input', 'select_input');
		sel_input.attr('name', 'new_fabric_info[][fabric_shop_id]');
		sel_input.attr('id', 'new_fabric_info[][fabric_shop_id]');
		sel_input.attr('class', 'input-3');
		var desc = $('<input type="text" class="input-3" name="new_fabric_info[][description]">');
		tr.find('td:eq(0)').append(desc);
		tr.find('td:eq(1)').append(init_select_input(sel_input));
		$('div.select-input').each(function(i) {
			$(this).css('z-index', $('div.select-input').length - i);
		});
		tr.css('background-color', '#F4F8FA');
		var add_fabric_shop = $('#add_fabric_shop');
		tr.insertAfter(add_fabric_shop.parents('tr'));
		if ($('input.btn-2[value="移除"]').length < 1) {
			add_fabric_shop.parent().append($('<input type="button" value="移除" class="btn-2" />'));
		}
		tr.find('td:eq(2)').append($('<input type="button" value="移除" class="btn-2" />'));
		tr.find('td:eq(2)').append(add_fabric_shop);
		$('input.btn-2[value="移除"]').click(function() {
			remove_fabric_shop($(this));
		});
		sort_new_fabric_info();
	});
	$('input.btn-2[value="移除"]').click(function() {
		remove_fabric_shop($(this));
	});
	$('#add_fabric_shop').click(function() {
		var value = $.trim(prompt("请输入布行/档口名称：", ''));
		if (value != '' && confirm('系统将增加此布行信息到系统，请确认是否重复。\r\n' + value + '\r\n确定要添加该布行吗？')) {
			$.post('index.php?app=fabric_shop&act=AjaxAdd', {'fabric_shop_name' : value}, function(json) {
				if (json.done) {
					ref_fabric_shop();
				}
				alert(json.msg);
			}, 'json');
		}
	});
	$('input[acttype="confirm"]').click(function() {
		if (confirm('是否已经保存信息？更新样板信息之后将会使已确认样板状态无效。\r\n\r\n是否继续？')) {
			$.getJSON('index.php?app=sample&act=confirm&id={$smarty.get.id}', function(json) {
				alert(json.msg);
			});
		}
	});
});

function sort_new_fabric_info()
{
	$('input[name^="new_fabric_info"][name$="[description]"]').each(function(i) {
		$(this).attr('name', 'new_fabric_info[' + i + '][description]');
	});
	$('input[name^="new_fabric_info"][name$="[fabric_shop_id]"]').each(function(i) {
		$(this).attr('name', 'new_fabric_info[' + i + '][fabric_shop_id]');
		$(this).attr('id', 'new_fabric_info[' + i + '][fabric_shop_id]');
	});
}

function remove_fabric_shop(_this)
{
	if (!confirm('确定要移除该面料信息吗？')) {
		return;
	}
	var add_fabric_shop = $('#add_fabric_shop');
	if ($('input.btn-2[value="移除"]').length == 1) {
		$('#add_fabric_info').click();
	}
	_this.parents('tr').remove();
	add_fabric_shop.insertAfter($('input.btn-2[value="移除"]:last'));
	sort_new_fabric_info();
}
</script>
<style type="text/css">
.btn-2{margin-bottom:5px;}
</style>
<body>
<div id="fabric_shop_data" style="display:none;"><select><!--{foreach from=$fabricshop_list item=fabric_shop}--><option value="{$fabric_shop.fabric_shop_id}">{$fabric_shop.fabric_shop_name|escape}</option><!--{/foreach}--></select></div>
<div class="sub-body">
      
  <div class="tab-frame">
  <h3 class="tab-title-1"><span>{$lang.sample_more_info}</span></h3>
		<form method="post" action="temp.php?id={$smarty.get.id}">
    <table cellspacing="0" cellpadding="0" class="tab-display">
      <tr>
        <th align="right">{$lang.arrival_date}：</th>
        <td class="tab-align-l">{$sample.arrival_date|date:Y-m-d}</td>
		<th colspan="4">{$lang.front_pic}</th>
		<th colspan="4">{$lang.other_pic}</th>
      </tr>
      <tr>
        <th align="right">{$lang.sample_sn}：</th>
        <td class="tab-align-l">{$sample.sample_sn}</td>
		<td colspan="4" rowspan="10"><img src="{$sample.front_pic}" id="front_pic_show" width="220" height="264" /><input type="hidden" name="front_pic" id="front_pic" value="" onChange="document.getElementById('front_pic_show').src=this.value;" /></td>
		<td colspan="4" rowspan="10"><img src="{$sample.other_pic}" id="other_pic_show" width="220" height="264" /><input type="hidden" name="other_pic" id="other_pic" value="" onChange="document.getElementById('other_pic_show').src=this.value;" /></td>
      </tr>
      <tr>
        <th align="right">{$lang.ref_sample_style}：</th>
        <td class="tab-align-l">{$lang.ref_sample_styles.$sample.ref_sample_style}</td>
      </tr>
      <tr>
        <th align="right">{$lang.brand_name}：</th>
        <td class="tab-align-l">{$sample.brand_name}</td>
      </tr>
      <tr>
        <th align="right">{$lang.buyer_name}：</th>
        <td class="tab-align-l">{$sample.buyer_name}</td>
      </tr>
      <tr>
        <th align="right">{$lang.merchandiser}：</th>
        <td class="tab-align-l">{$sample.user_name}</td>
      </tr>
      <tr>
        <th align="right">{$lang.style_name}：</th>
        <td class="tab-align-l"><select name="sample[style_id]">
			<option value="0">请选择...</option>
			<!--{foreach from=$style_list item=style}-->
			<option value="{$style.style_id}"{if $sample.style_id == $style.style_id} selected{/if}>{$style.style_name|escape}</option>
			<!--{/foreach}-->
		</select></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <th colspan="10" align="left" style="padding:5px; font-size:14px;">{$lang.fabric_info}：</th>
      </tr>
	  <!--{if $fabric_info_list}-->
	  <!--{foreach from=$fabric_info_list item=fabric_info name=fi}-->
      <tr>
        <th align="right">{$lang.desc}：</th>
        <td class="tab-align-l"><input type="text" class="input-1" name="old_fabric_info[{$fabric_info.fabric_info_id}][description]" value="{$fabric_info.description|escape}"></td>
        <th align="right">{$lang.fabric_shop_name}：</th>
        <td class="tab-align-l" colspan="3"><select select_input="select_input" name="old_fabric_info[{$fabric_info.fabric_info_id}][fabric_shop_id]" id="old_fabric_info[{$fabric_info.fabric_info_id}][fabric_shop_id]" class="input-3" val="{$fabric_info.fabric_shop_id}">
		  	<!--{foreach from=$fabricshop_list item=fabric_shop}-->
			<option value="{$fabric_shop.fabric_shop_id}">{$fabric_shop.fabric_shop_name|escape}</option>
			<!--{/foreach}-->
		</select></td>
		<td colspan="4" align="left"><input type="button" class="btn-2" value="移除"><!--{if $smarty.foreach.fi.last}--><input type="button" class="btn-2" value="增加布行" id="add_fabric_shop" /><!--{/if}--></td>
      </tr>
	  <!--{/foreach}-->
	  <!--{else}-->
      <tr>
        <th align="right">{$lang.desc}：</th>
        <td class="tab-align-l"><input type="text" class="input-1" name="new_fabric_info[0][description]"></td>
        <th align="right">{$lang.fabric_shop_name}：</th>
        <td class="tab-align-l" colspan="3"><select select_input="select_input" name="new_fabric_info[0][fabric_shop_id]" id="new_fabric_info[0][fabric_shop_id]" class="input-3">
		  	<!--{foreach from=$fabricshop_list item=fabric_shop}-->
			<option value="{$fabric_shop.fabric_shop_id}">{$fabric_shop.fabric_shop_name|escape}</option>
			<!--{/foreach}-->
		</select></td>
		<td colspan="4" align="left"><input type="button" class="btn-2" value="增加布行" id="add_fabric_shop" /></td>
      </tr>
	  <!--{/if}-->
      <tr>
        <th align="right">{$lang.color_card}：</th>
        <td class="tab-align-l" colspan="3" id="color_card"><!--{foreach from=$sample.colorcard_files item=file}-->
		<a href="download.php?id={$file.file_id}">{$file.file_name}</a><a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a><!--{if !$smarty.foreach.last}--><br /><!--{/if}-->
		<!--{/foreach}--></td>
        <td class="tab-align-l" colspan="6"></td>
      </tr>
      <tr>
        <td colspan="10">&nbsp;</td>
      </tr>
      <tr>
        <th align="right" width="80">{$lang.factory_name}：</th>
        <td class="tab-align-l" width="120">{$sample.factory_name}</td>
        <th align="right" width="80">{$lang.to_factory_date}：</th>
        <td class="tab-align-l" width="120">{$sample.to_factory_date|date:Y-m-d}</td>
        <th align="right" width="80">{$lang.send_sample_date}：</th>
        <td class="tab-align-l" width="120">{$sample.send_sample_date|date:Y-m-d}</td>
        <th align="right" width="80">{$lang.factory_price}：</th>
        <td class="tab-align-l" width="120">{$sample.factory_price|escape}</td>
        <th align="right" width="80">{$lang.quotation}：</th>
        <td class="tab-align-l" width="120" id="factory_files" rowspan="2"><!--{foreach from=$sample.factory_files item=file}-->
		<a href="download.php?id={$file.file_id}">{$file.file_name}</a><a class="pic_del" href="{url app=comupload&act=delete&id=$file.file_id}" onClick="return confirm('{$lang.confirm_del_file}')" title="{$lang.delete}">&nbsp;</a><!--{if !$smarty.foreach.last}--><br /><!--{/if}-->
		<!--{/foreach}--></td>
      </tr>
	  <tr>
	    <td colspan="8">&nbsp;</td>
	  </tr>
      <tr>
        <th align="right">{$lang.description}：</th>
        <td class="tab-align-l" colspan="6"><textarea name="sample[description]" style="width:400px;height:100px;">{$sample.description|escape}</textarea></td>
		<td colspan="3"><input type="submit" class="btn-2" value="更新"></td>
      </tr>
    </table>
	</form>
  </div>
</div>
<script language="javascript" type="text/javascript" src="{res file=js/tab_color.js}"></script>
</body>
</html>